package com.agranee.timemanagementsystem.dao;

import java.util.Date;

import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;

import com.agranee.timemanagementsystem.entity.Employee;
import com.agranee.timemanagementsystem.exception.TimeManagementSystemException;
import com.agranee.timemanagementsystem.util.HibernateUtil;

public class EmployeeDao {
	private static final Logger logger=Logger.getLogger(EmployeeDao.class);

	/*
	 * The following function will return the employee instance associated with
	 * the passed User Id
	 */

	public Employee getEmployeeByUserId(String userId) {
		logger.info("Retriving user based on userId at : "+new Date());
		Employee employee=null;
		Session session=null;
		
		 session = HibernateUtil.getSessionfactory().openSession();
		session.beginTransaction();
		Query query = session
				.createQuery("from Employee e where e.employeeUserId=:userId");
		query.setParameter("userId", userId);
		employee = (Employee) query.uniqueResult();
		session.close();
	
		return employee;
	}
	public Employee getEmployeeEmployeeId(String employeeId) {
		logger.info("Retriving user based on employeeId at : "+new Date());
		Employee employee=null;
		Session session=null;
		
		 session = HibernateUtil.getSessionfactory().openSession();
		session.beginTransaction();
		Query query = session
				.createQuery("from Employee e where e.employeeId=:employeeId");
		query.setParameter("employeeId", employeeId);
		employee = (Employee) query.uniqueResult();
		session.close();
	
		return employee;
	}
/*	public Employee getEmployeeByEmailId(String emailId) {
		logger.info("Retriving user based on emailId at : "+new Date());
		System.out.println("Found email : "+emailId);
		Employee employee=null;
		Session session=null;
		
		 session = HibernateUtil.getSessionfactory().openSession();
		session.beginTransaction();
		Query query = session
				.createQuery("from Employee e where e.employeeEmailId=:emailId");
		query.setParameter("emailId", emailId.trim());
		employee = (Employee) query.uniqueResult();
		System.out.println("Employee Name : "+employee.getEmployeeName());
		session.close();
	
		return employee;
	}*/
	
}